<script src="/js/commentsRev.js"></script>
<?php
    function printSubComments($target, $comments, $level, $countMessagesData) {
        $level++;
          for($i=0; $i<count($comments); $i++) {
            if($target['comId'] == $comments[$i]['parentId']) {
                if($level < 7) {
                     echo '<ul class="comments">';
                } 
                echo '<a style="padding-top:65px;" id="com'.$comments[$i]['comId'].'"></a>';
                echo '<li id="comment'.$comments[$i]['comId'].'">'; 
                echo '<div class="comment_head">';           
                echo '<a id="com'.$comments[$i]['comId'].'"';
                if(!Yii::app()->user->isGuest){ echo 'class="comment_otv"';} 
                echo 'href="#com'.$comments[$i]['comId'].'">#</a>&nbsp;&nbsp;';
                
                echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']).'&nbsp;&nbsp;&nbsp;';
                   $login = !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login'];
                echo '<a href="'.Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])).'">'.$login.'</a>&nbsp;';  
                
                if(!empty($countMessagesData)) {
                    $count = 0;
                     foreach ($countMessagesData as $countMessages) : 
                        if($countMessages['userId'] == $comments[$i]['comUid']) {
                            $count = $countMessages['reviews'] + $countMessages['newsComments'] + $countMessages['forumComments'] + $countMessages['revComments'] + $countMessages['blogComments'];
                        }
                    endforeach;

                    echo '<span class="comment_numb">'.$count.'</span>';
                }
               
                
               
                echo '  </div> ';   
                
                echo '<div class="comment_body"><p>';
                echo $comments[$i]['text'];
               
                echo'</p> ';
               
                if(!Yii::app()->user->isGuest) :
                  echo '<a href="#comment-form" class="comment_otv">Ответить</a> ';
                endif;
                echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId'));
               
               
                echo'</div>';
                printSubComments($comments[$i], $comments, $level, $countMessagesData);
                echo '</li>';
                if($level < 7) echo '</ul>';
            }
        }
       
    }
?>

<div class="padding4020">
    <h2 class="profil_h2"><?php echo $cat['name']; ?></h2>
    
    <?php if(!empty($cat['about'])) : ?>
        <div class="pull-left" style="width:500px;margin-bottom: 20px;">
            <?php $data = split('<more>', $cat['about']); ?>
            <?php echo $data[0]; ?>
            <?php if(!empty($data[1])) : ?>
                <span class="aboutMore"> <?php echo $data[1]; ?> </span>
               <a href="javascrip:void(0);"id="showAboutMore">Читать дальше &rarr;</a>
            <?php endif; ?>
        </div>        
    <?php endif; ?>
    <span class="cat_banner pull-right ">
        <?php if(!empty($this->advertCode)) : ?>
            <?php echo $this->advertCode; ?>
        <?php else : ?>
            <img src="/images/banners/cat_banner.png" alt="">
        <?php endif; ?>
    </span>
    <div class="clearfix"></div>
    
   <!-- Если в этой категории есть подкатегории нужно их тут выводить и знаю какая из них сейчас  -->
   <?php if(!empty($catSubCats)) : ?>
       <div class="pull-left">
            <ul class="unstyled subcat_menu ">
                <?php foreach ($catSubCats as $item) : ?>
                    <li <?php echo $item['catId'] == $cat['catId'] ? 'class="btn"' : '' ?> > 
                        <a href="<?php echo Yii::app()->createUrl('partner/news/allCatNews', array('catId'=>$item['catId'])); ?>"><?php echo $item['name']; ?></a>
                    </li>
                <?php endforeach; ?>
            </ul>         
       </div> 
   <?php endif; ?> 
<div class="clearfix"></div>   

</div>

<?php $params = isset($_GET['parentId']) ? array('parentId'=>$_GET['parentId'], 'catId'=>$cat['catId']) : array('catId'=>$cat['catId']); ?>    

<ul id="tabs">
<li class="first ">
     <a class="befor_activ_tab" href="<?php echo Yii::app()->createUrl('partner/default/cat', $cat['parentId'] ? array('catId'=>$cat['catId'], 'parentId'=>$cat['parentId']) : array('catId'=>$cat['catId'])); ?>">Рейтинг</a>
    </li>
<li class="activ_tab"> 
            <a class="" href="<?php echo Yii::app()->createUrl('partner/news/allCatNews', $params); ?>">Новости и аналитика</a>
    </li> 
<li class="">  
            <a class="last" href="<?php echo Yii::app()->createUrl('partner/default/topForums', $params); ?>">Топ Мини-форумов</a>
    </li>
</ul>

<div class="tabs_wraper"></div>


<div class="padding4020">
<div class="news_singl">
     <div class="news_date"><?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года", $news['date']); ?></div>
    <h1 class="news_title"><?php echo $news['title']; ?></h1>
    
    <?php echo $news['text']; ?>
   
   
</div>
  <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" style="margin-bottom:20px;" class="comment_otv">Комментировать</a>
                    <?php endif; ?>
</div>




<?php if(!empty($comments)) : ?>
<div class="padding040">

<h2 class="com_head">Комментарии</h2>
</div>
 


 <?php for($i = 0; $i<count($comments); $i++) : ?>
        <?php // if($comments[$i]['isDelegate']) continue; ?>
            <?php if(!$comments[$i]['parentId']) : ?>
            <ul class="comments">
                <a style="padding-top:65px;" id="com<?php echo $comments[$i]['comId']; ?>"></a>
                <li id="comment<?php echo $comments[$i]['comId'];  ?>">
                <div class="comment_head"><a href="#com<?php echo $comments[$i]['comId'];  ?>">#</a>&nbsp;&nbsp;<?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $comments[$i]['date']); ?>&nbsp;&nbsp;&nbsp;
                   
                     <a href="<?php echo Yii::app()->createUrl('user/profile/profile', array('login'=>$comments[$i]['login'])); ?>"><?php echo !empty($comments[$i]['displayName']) ? $comments[$i]['displayName'] : $comments[$i]['login']; ?></a>&nbsp;

                    <?php 
                    if(!empty($countMessagesData)) {
                        $count =0;
                        foreach ($countMessagesData as $countMessages) : 
                            if($countMessages['userId'] == $comments[$i]['comUid']) {
                                $count = $countMessages['reviews'] + $countMessages['newsComments'] + $countMessages['forumComments'] + $countMessages['revComments'] + $countMessages['blogComments'];
                            }
                        endforeach; ?>
                     <span class="comment_numb"><?php echo $count; ?></span> 
                    <?php  } ?>
                         
                    


                    
                   
                   
                    </div>    
                        
                    <div class="comment_body"><p><?php echo $comments[$i]['text']; ?></p>
                          <?php if(!Yii::app()->user->isGuest) : ?>
                        <a href="#comment-form" class="comment_otv">Ответить</a>
                    <?php endif; ?>
                         <?php echo CHtml::hiddenField('', $comments[$i]['comId'], array('class'=>'comId')); ?>
                  
                      
                        
                        
                  
                    </div>
                   
                   
                    
                    <?php printSubComments($comments[$i], $comments, 1, !empty($countMessagesData) ? $countMessagesData : ''); ?>
                </li>
                </ul> 
            <?php endif; ?>
    <?php endfor; ?>

<?php endif; ?>




<div class="padding4020">
     
    
    
    
               <div  id="comment-form" class="hiddenForm hide">   
<div class="comment_form_cut"></div>
<div  class="comment_form">
    <?php echo CHtml::beginForm(); ?>
<span class="pull-right close_form"></span>
<div class="clearfix"></div>
<div class="pull-left mar_top10">
    <div class="user_av_form_rew pull-left">
                <?php if (Yii::app()->user->getState('avatar')) : ?>
                    <img alt="" src="/images/uploads/userAvatars/<?php echo Yii::app()->user->getState('avatar'); ?>" style="height:28px; width:28px;" alt="" />
                <?php else : ?>
                    <img src="/images/prettyImg/default-avatarl.jpg"  style="height:28px; width:28px;" alt="" />
                <?php endif; ?> 
     </div>  
    <div class="pull-left">
    <?php echo CHtml::activeTextArea($model, 'text', array('class'=>'text_area_comm', 'id'=>'editor')); ?>
    </div>    

</div>

        
        
  <div class="clearfix"></div> 
  
       
  <div class="pull-left mar-top20" style="margin-left:40px;">
    <?php echo CHtml::submitButton('Добавить комментарий',array('class'=>'addpst')); ?> 
   </div>
   
    <?php echo CHtml::activeHiddenField($model, 'parentId', array('value'=>'', 'class'=>'comParentId')); ?><br/>
    <?php echo CHtml::activeHiddenField($model, 'newsId', array('value'=>$news['newsId'])); ?><br/>
    <?php echo CHtml::endForm(); ?>
      
        
</div>
</div>


</div>



    
    
    